package Arrays;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class _78_Subsets {
    List<List<Integer>> totalList =new ArrayList<List<Integer>>();
    public List<List<Integer>> subsets(int[] nums) {
        totalList.add(new ArrayList<Integer>());
        boolean[] visited =new boolean[nums.length];
        for(int i=1;i<=nums.length;i++) {
            getList(nums,0,0,i,visited,new ArrayList<Integer>());
        }
        return totalList;
    }

    public void getList(int[] nums,int pos,int count, int N, boolean[] visited,List<Integer> curList) {
        if (count == N) {
            totalList.add(curList);
        }
        for(int i=pos;i<nums.length;i++) {
            if (!visited[i]) {
                visited[i] = true;
                List<Integer> tpList = new ArrayList<Integer>();
                tpList.add(nums[i]);
                tpList.addAll(curList);
                getList(nums,i+1,count+1,N,visited,tpList);

                visited[i] = false;
            }
        }
    }

    @Test
    public void test() {
        int[] nums = {1,2,3};
        boolean[] visited =new boolean[nums.length];
        getList(nums,0,0,2,visited,new ArrayList<>());
        System.out.println(totalList.toString());
    }
}
